{"ast":null,"code":"import _slicedToArray from \"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";\nimport _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nimport areArraysEqual from '../utils/areArraysEqual';\n/**\n * Gets the current state. If the selectedValue is controlled,\n * the `value` prop is the source of truth instead of the internal state.\n */\n\nfunction getControlledState(internalState, props) {\n  if (props.value !== undefined) {\n    return _extends({}, internalState, {\n      selectedValue: props.value\n    });\n  }\n  return internalState;\n}\nfunction areOptionsEqual(option1, option2, optionComparer) {\n  if (option1 === option2) {\n    return true;\n  }\n  if (option1 === null || option2 === null) {\n    return false;\n  }\n  return optionComparer(option1, option2);\n}\n/**\n * Triggers change event handlers when reducer returns changed state.\n */\n\nfunction useStateChangeDetection(nextState, internalPreviousState, propsRef, lastActionRef) {\n  React.useEffect(function () {\n    if (!propsRef.current || lastActionRef.current === null) {\n      // Detect changes only if an action has been dispatched.\n      return;\n    }\n    var previousState = getControlledState(internalPreviousState, propsRef.current);\n    var _propsRef$current2 = propsRef.current,\n      multiple = _propsRef$current2.multiple,\n      optionComparer = _propsRef$current2.optionComparer;\n    if (multiple) {\n      var _previousState$select;\n      var previousSelectedValues = (_previousState$select = previousState == null ? void 0 : previousState.selectedValue) != null ? _previousState$select : [];\n      var nextSelectedValues = nextState.selectedValue;\n      var onChange = propsRef.current.onChange;\n      if (!areArraysEqual(nextSelectedValues, previousSelectedValues, optionComparer)) {\n        onChange == null ? void 0 : onChange(lastActionRef.current.event, nextSelectedValues);\n      }\n    } else {\n      var previousSelectedValue = previousState == null ? void 0 : previousState.selectedValue;\n      var nextSelectedValue = nextState.selectedValue;\n      var _onChange = propsRef.current.onChange;\n      if (!areOptionsEqual(nextSelectedValue, previousSelectedValue, optionComparer)) {\n        _onChange == null ? void 0 : _onChange(lastActionRef.current.event, nextSelectedValue);\n      }\n    } // Fires the highlightChange event when reducer returns changed `highlightedValue`.\n\n    if (!areOptionsEqual(internalPreviousState.highlightedValue, nextState.highlightedValue, propsRef.current.optionComparer)) {\n      var _propsRef$current, _propsRef$current$onH;\n      (_propsRef$current = propsRef.current) == null ? void 0 : (_propsRef$current$onH = _propsRef$current.onHighlightChange) == null ? void 0 : _propsRef$current$onH.call(_propsRef$current, lastActionRef.current.event, nextState.highlightedValue);\n    }\n    lastActionRef.current = null;\n  }, [nextState.selectedValue, nextState.highlightedValue, internalPreviousState, propsRef, lastActionRef]);\n}\nexport default function useControllableReducer(internalReducer, externalReducer, props) {\n  var _ref;\n  var value = props.value,\n    defaultValue = props.defaultValue;\n  var propsRef = React.useRef(props);\n  propsRef.current = props;\n  var actionRef = React.useRef(null);\n  var initialSelectedValue = (_ref = value === undefined ? defaultValue : value) != null ? _ref : props.multiple ? [] : null;\n  var initalState = {\n    highlightedValue: null,\n    selectedValue: initialSelectedValue\n  };\n  var combinedReducer = React.useCallback(function (state, action) {\n    actionRef.current = action;\n    if (externalReducer) {\n      return externalReducer(getControlledState(state, propsRef.current), action);\n    }\n    return internalReducer(getControlledState(state, propsRef.current), action);\n  }, [externalReducer, internalReducer, propsRef]);\n  var _React$useReducer = React.useReducer(combinedReducer, initalState),\n    _React$useReducer2 = _slicedToArray(_React$useReducer, 2),\n    nextState = _React$useReducer2[0],\n    dispatch = _React$useReducer2[1];\n  var previousState = React.useRef(initalState);\n  React.useEffect(function () {\n    previousState.current = nextState;\n  }, [previousState, nextState]);\n  useStateChangeDetection(nextState, previousState.current, propsRef, actionRef);\n  return [getControlledState(nextState, propsRef.current), dispatch];\n}","map":{"version":3,"names":["_extends","React","areArraysEqual","getControlledState","internalState","props","value","undefined","selectedValue","areOptionsEqual","option1","option2","optionComparer","useStateChangeDetection","nextState","internalPreviousState","propsRef","lastActionRef","useEffect","current","previousState","multiple","_previousState$select","previousSelectedValues","nextSelectedValues","onChange","event","previousSelectedValue","nextSelectedValue","highlightedValue","_propsRef$current","_propsRef$current$onH","onHighlightChange","call","useControllableReducer","internalReducer","externalReducer","_ref","defaultValue","useRef","actionRef","initialSelectedValue","initalState","combinedReducer","useCallback","state","action","useReducer","dispatch"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@mui/base/ListboxUnstyled/useControllableReducer.js"],"sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nimport areArraysEqual from '../utils/areArraysEqual';\n/**\n * Gets the current state. If the selectedValue is controlled,\n * the `value` prop is the source of truth instead of the internal state.\n */\n\nfunction getControlledState(internalState, props) {\n  if (props.value !== undefined) {\n    return _extends({}, internalState, {\n      selectedValue: props.value\n    });\n  }\n\n  return internalState;\n}\n\nfunction areOptionsEqual(option1, option2, optionComparer) {\n  if (option1 === option2) {\n    return true;\n  }\n\n  if (option1 === null || option2 === null) {\n    return false;\n  }\n\n  return optionComparer(option1, option2);\n}\n/**\n * Triggers change event handlers when reducer returns changed state.\n */\n\n\nfunction useStateChangeDetection(nextState, internalPreviousState, propsRef, lastActionRef) {\n  React.useEffect(() => {\n    if (!propsRef.current || lastActionRef.current === null) {\n      // Detect changes only if an action has been dispatched.\n      return;\n    }\n\n    const previousState = getControlledState(internalPreviousState, propsRef.current);\n    const {\n      multiple,\n      optionComparer\n    } = propsRef.current;\n\n    if (multiple) {\n      var _previousState$select;\n\n      const previousSelectedValues = (_previousState$select = previousState == null ? void 0 : previousState.selectedValue) != null ? _previousState$select : [];\n      const nextSelectedValues = nextState.selectedValue;\n      const onChange = propsRef.current.onChange;\n\n      if (!areArraysEqual(nextSelectedValues, previousSelectedValues, optionComparer)) {\n        onChange == null ? void 0 : onChange(lastActionRef.current.event, nextSelectedValues);\n      }\n    } else {\n      const previousSelectedValue = previousState == null ? void 0 : previousState.selectedValue;\n      const nextSelectedValue = nextState.selectedValue;\n      const onChange = propsRef.current.onChange;\n\n      if (!areOptionsEqual(nextSelectedValue, previousSelectedValue, optionComparer)) {\n        onChange == null ? void 0 : onChange(lastActionRef.current.event, nextSelectedValue);\n      }\n    } // Fires the highlightChange event when reducer returns changed `highlightedValue`.\n\n\n    if (!areOptionsEqual(internalPreviousState.highlightedValue, nextState.highlightedValue, propsRef.current.optionComparer)) {\n      var _propsRef$current, _propsRef$current$onH;\n\n      (_propsRef$current = propsRef.current) == null ? void 0 : (_propsRef$current$onH = _propsRef$current.onHighlightChange) == null ? void 0 : _propsRef$current$onH.call(_propsRef$current, lastActionRef.current.event, nextState.highlightedValue);\n    }\n\n    lastActionRef.current = null;\n  }, [nextState.selectedValue, nextState.highlightedValue, internalPreviousState, propsRef, lastActionRef]);\n}\n\nexport default function useControllableReducer(internalReducer, externalReducer, props) {\n  var _ref;\n\n  const {\n    value,\n    defaultValue\n  } = props;\n  const propsRef = React.useRef(props);\n  propsRef.current = props;\n  const actionRef = React.useRef(null);\n  const initialSelectedValue = (_ref = value === undefined ? defaultValue : value) != null ? _ref : props.multiple ? [] : null;\n  const initalState = {\n    highlightedValue: null,\n    selectedValue: initialSelectedValue\n  };\n  const combinedReducer = React.useCallback((state, action) => {\n    actionRef.current = action;\n\n    if (externalReducer) {\n      return externalReducer(getControlledState(state, propsRef.current), action);\n    }\n\n    return internalReducer(getControlledState(state, propsRef.current), action);\n  }, [externalReducer, internalReducer, propsRef]);\n  const [nextState, dispatch] = React.useReducer(combinedReducer, initalState);\n  const previousState = React.useRef(initalState);\n  React.useEffect(() => {\n    previousState.current = nextState;\n  }, [previousState, nextState]);\n  useStateChangeDetection(nextState, previousState.current, propsRef, actionRef);\n  return [getControlledState(nextState, propsRef.current), dispatch];\n}"],"mappings":";AAAA,OAAOA,QAAQ,MAAM,oCAAoC;AACzD,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,OAAOC,cAAc,MAAM,yBAAyB;AACpD;AACA;AACA;AACA;;AAEA,SAASC,kBAAkB,CAACC,aAAa,EAAEC,KAAK,EAAE;EAChD,IAAIA,KAAK,CAACC,KAAK,KAAKC,SAAS,EAAE;IAC7B,OAAOP,QAAQ,CAAC,CAAC,CAAC,EAAEI,aAAa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